//
//  HelpViewController.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/3/2.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "HelpViewController.h"
#import "AppHeader.h"

#import "HelpCenterModel.h"

@interface HelpViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray<HelpCenterModel *> *dataArray;

@end

@implementation HelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _getHelpCenterData];
//    self.dataArray =@[@"如何获得金豆?", @"抓到后怎么获得奖品或兑换金豆?", @"游戏中出现故障/问题怎么办?"].mutableCopy;
}

- (void)_getHelpCenterData {
    [HttpUrl GET:@"helpCenter/selectPage1" dict:nil hud:self.view isShow:YES WithSuccessBlock:^(id data) {
        if (BB_isSuccess) {
            NSArray *arr = data[@"data"][@"list"];
            for (NSDictionary *dic in arr) {
                HelpCenterModel *model = [HelpCenterModel mj_objectWithKeyValues:dic];
                [self.dataArray addObject:model];
            }
            [self.tableView reloadData];
        } else {
            ShowAlertTitle(@"暂无帮助");
        }
        
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.frame), 0.1)];
    headerView.backgroundColor =tableView.backgroundColor;
    return headerView;
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footerView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.1)];
    footerView.backgroundColor =tableView.backgroundColor;
    
    return footerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text =_dataArray[indexPath.row].title;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    QZMessageDetailVC *messageVC =[[QZMessageDetailVC alloc]init];
    messageVC.title =self.dataArray[indexPath.row].title;
    messageVC.htmlStr =_dataArray[indexPath.row].content;
    [self.navigationController pushViewController:messageVC animated:YES];
}

#pragma mark - Property Override
-(NSMutableArray<HelpCenterModel *> *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
